package com.neuedu.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.neuedu.common.ResultJson;
import com.neuedu.entity.Employee;
import com.neuedu.service.DepartmentService;
import com.neuedu.service.EmployeeService;
import com.neuedu.service.RegistLevelService;
import com.neuedu.service.SchedulingService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 员工表 前端控制器
 * </p>
 *
 * @author LiYang
 * @since 2024-11-07
 */
@RestController
@RequestMapping("/employee")
public class EmployeeController {
    @Resource
    EmployeeService employeeService;
    @Resource
    DepartmentService departmentService;
    @Resource
    RegistLevelService registLevelService;
    @Resource
    SchedulingService schedulingService;

    @GetMapping("/getEditData")
    ResultJson<Map<String, List<?>>> getEditData () {
        Map<String, List<?>> map = new HashMap<>();
        map.put("depts", departmentService.getActive());
        map.put("regists", registLevelService.getActive());
        map.put("schedulings", schedulingService.getActive());
        return ResultJson.success(map);
    }

    /**
     *  分页查询员工信息
     */
    @GetMapping("/list")
    ResultJson<IPage<Employee>> list(Integer pageNo, Integer pageSize, String name) {
        return ResultJson.success(employeeService.list(pageNo, pageSize, name));
    }

    /**
     *  校验字段是否重复
     */
    @GetMapping("/check")
    ResultJson<Boolean> check(String field, String value, Long id) {
        return ResultJson.success(employeeService.check(field, value, id));
    }

    /**
     *  添加员工
     */
    @PostMapping("/add")  // MultipartFile 文件的类型
    ResultJson<Boolean> add(Long deptmentId, Long registLevelId, Long schedulingId, String realname, String phone, String email, String password, MultipartFile file){
        return ResultJson.success(employeeService.add(deptmentId, registLevelId, schedulingId, realname, phone, email, password, file), "添加员工成功");
    }

    /**
     * 获取当前可挂号的医生
     */
    @GetMapping("/getRegisterEmp")
    ResultJson<List<Employee>> getRegisterEmp(Integer week, String noon, Long deptId, Long registLevelId) {
        return ResultJson.success(employeeService.getRegisterEmp(week, noon, deptId, registLevelId));
    }
    @PostMapping("/login")
    ResultJson<String> login(String username,String password){
        return ResultJson.success(employeeService.login(username, password));
    }
    @GetMapping("/getNameById")
    String getNameById(Long id) {
        return employeeService.getById(id).getRealname();
    }
    @PostMapping("/getEmplogin")
    ResultJson<Employee> getEmplogin(String username, String password) {
        return ResultJson.success(employeeService.getByPhonePass(username, password));
    }
}
